package com.eksboot;

import com.eksframework.commons.core.base.EksDate;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler;
import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
import com.google.common.collect.Lists;
import lombok.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;

import java.io.IOException;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.LongStream;

/**
 * Test
 *
 * @author: chenfenghai
 * @version: 1.0
 * @date: 2020-04-10 15:36
 */
@Slf4j
public class Test {


    public static void main(String[] args) throws JsonProcessingException {
        System.out.println(StringUtils.trimToNull(" "));

        System.out.println("done.");
    }

    @SneakyThrows
    public static void throwException(){
        DateUtils.parseDate("2021-12", "yyyy-MM-dd");
        Integer i = null;
        System.out.println(i.toString());
    }

}
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode
@ToString
class VO{
    private Long id;
    private String name;
    private Long brandId;

    @JsonDeserialize(using = DateJsonDeserializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;
}

class DateJsonDeserializer extends JsonDeserializer<Date> {

    @Override
    public Date deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        System.out.println("deserialize: "+p.getText());
        if(!EksDate.isDateTimeFormat(p.getText(), EksDate.PATTERN_YYYYMMDDHHMMSS)){
            throw new IOException("日期格式不正确");
        }
        return EksDate.of(p.getText(), EksDate.PATTERN_YYYYMMDDHHMMSS).toDate();
    }
}
